# -*-coding:utf-8-*-
import numpy as np
import math
'''
around(arr,decimals=?)？表示保留多少位小数
'''


class Datanorm:
    def __init__(self,arr):
        self.arr = np.array(arr)
        self.x_max = self.arr.max() #数组元素中的最大值
        self.x_min = self.arr.min() #数组元素中的最小值
        self.x_mean = self.arr.mean() # 数组元素中平均值
        self.x_std = self.arr.std() #数组元素中的标准差

    def Min_MaxNorm(self):
        arr = np.around(((self.arr - self.x_min) / (self.x_max - self.x_min)), decimals=4)
        # print("Min_Max标准化:{}".format(arr))
        return arr

    def Z_ScoreNorm(self):
        arr = np.around((self.arr - self.x_mean) / self.x_std, decimals=4)
        return arr
        # print("Z_Score标准化:{}".format(arr))

    def Decimal_ScalingNorm(self):
        power = 1
        maxValue = self.x_max
        while maxValue / 10 >= 1.0:
            power += 1
            maxValue /= 10
        arr = np.around((self.arr / pow(10, power)), decimals=4)
        return arr

    def MeanNorm(self):
        first_arr = np.around((self.arr-self.x_mean) / (self.x_max - self.x_min), decimals=4)
        second_arr = np.around((self.arr - self.x_mean)/self.x_max, decimals=4)
        return first_arr
        print("均值归一法：\n公式一:{}\n公式二:{}".format(first_arr, second_arr))

    def Vector(self):
        arr = np.around((self.arr/self.arr.sum()), decimals=4)
        print("向量归一法:{}".format(arr))

    def exponeential(self):

        first_arr = np.around(np.log10(self.arr) / np.log10(self.x_max), decimals=4)
        second_arr = np.around(np.exp(self.arr)/sum(np.exp(self.arr)), decimals=4)
        three_arr = np.around(1/(1+np.exp(-1*self.arr)), decimals=4)
        print("lg函数:{}\nSoftmax函数:{}\nSigmoid函数:{}\n".format(first_arr,second_arr,three_arr))


if __name__ == "__main__":
    a = Datanorm([1,2,3,4,5,6,7,8,9])
    a.Min_MaxNorm()
    exit()
    a.Z_ScoreNorm()
    a.Decimal_ScalingNorm()
    a.MeanNorm()
    a.Vector()
    a.exponeential()

